home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / frame3.exe / STATIC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-02-13  |  8.0 KB  |  278 lines

  1.  
  2. {$A+}   { Align data }
  3. {$B-}   { Boolean evaluation }
  4. {$E+}   { 80x87 emulator }
  5. {$F-}   { Force FAR calls }
  6. {$G+}   { 80286 code }
  7. {$I-}   { I/O checking }
  8. {$K+}   { Smart Callbacks }
  9. {$N-}   { 80x87 code }
  10. {$O-}   { Overlays allowed }
  11. {$P-}   { Open parameters }
  12. {$T-}   { Typed pointers }
  13. {$V-}   { String VAR checking }
  14. {$W-}   { Windows stack frame for real mode }
  15. {$X+}   { Extended syntax }
  16.  
  17. {$IFDEF DEBUG}
  18.     {$D+}   { Debug information }
  19.     {$L+}   { Local symbols }
  20.     {$Q+}   { Overflow checking }
  21.     {$R+}   { Range checking }
  22.     {$S+}   { Stack checking }
  23.     {$Y+}   { Symbol reference information }
  24. {$ELSE}
  25.     {$D-}   { Debug information }
  26.     {$L-}   { Local symbols }
  27.     {$Q-}   { Overflow checking }
  28.     {$R-}   { Range checking }
  29.     {$S-}   { Stack checking }
  30.     {$Y-}   { Symbol reference information }
  31. {$ENDIF}
  32.  
  33. {$C Moveable Demandload Discardable} { Code Segment attributes }
  34.  
  35. {$M 8192,4096}
  36.  
  37. PROGRAM StaticTest;
  38.  
  39. {
  40.   Copyright (c) 1993 by Olaf He▀ (Hess), Munich, Germany.
  41.  
  42.   Please feel free to use this code in your own programs.
  43.   If you make $$$ with it ->> You have my ID!
  44.   If you find any bugs or do any changes to the source code that you find
  45.   generally useful please send me a message to my CompuServe account
  46.   100 031, 35 36.
  47.  
  48.   Thanks.
  49. }
  50.  
  51. {$R STATIC.RES}
  52.  
  53. {$D StaticTest by Olaf Hess}
  54.  
  55. USES WinTypes, WinProcs, OWindows, ODialogs, WinDos, CommDlg,
  56.      FrameDlg, Stat_Ids;
  57.  
  58. CONST
  59.     szAppName = 'StaticTest';
  60.     szClassName = 'StaticTestClass';
  61.  
  62. TYPE
  63.     TStaticApp = OBJECT (TApplication)
  64.         PROCEDURE InitMainWindow; VIRTUAL;
  65.     END; { TStaticApp }
  66.  
  67.     PStaticWindow = ^TStaticWindow;
  68.     TStaticWindow = OBJECT (TSteelDlgWnd)
  69.         pToStaticUp : PStaticUp;
  70.         pToStaticDown : PStaticDown;
  71.         pToFrameUp : PFrameUp;
  72.         pToFrameDown : PFrameDown;
  73.  
  74.         CONSTRUCTOR Init (AParent: PWindowsObject; ATitle: PChar);
  75.  
  76.         PROCEDURE SetupWindow; VIRTUAL;
  77.         PROCEDURE GetWindowClass (VAR AWndClass: TWndClass); VIRTUAL;
  78.         FUNCTION GetClassName : PChar; VIRTUAL;
  79.  
  80.         PROCEDURE wmCommand (VAR Msg: TMessage);
  81.             VIRTUAL wm_First + wm_Command;
  82.  
  83.         PROCEDURE idChooseFile (VAR Msg: TMessage);
  84.             VIRTUAL id_First + id_ChooseFile;
  85.     END; { TStaticWindow }
  86.  
  87. (* ---- *)
  88.  
  89. FUNCTION FileOpenHook (hDlgWin: hWnd; Msg, wParam: Word;
  90.                        lParam: LongInt) : Word; EXPORT;
  91. { Hook procedure for the common dialog file open dialog. Note that this
  92.   function has to be marked as EXPORT and that Smart Callbacks must be
  93.   enabled: $K+ }
  94.  
  95. BEGIN
  96.     FileOpenHook := 0; { Default processing }
  97.  
  98.     CASE Msg OF
  99.         wm_InitDialog : FileOpenHook := 1; { Don't pass through }
  100.  
  101.         wm_CtlColor :
  102.             BEGIN
  103.                 IF (NOT fDoColors) THEN Exit; { Enough colors? }
  104.  
  105.                 CASE HiWord (lParam) OF
  106.  
  107.                     CtlColor_Dlg :
  108.                         { Brush for the dialog background }
  109.                         FileOpenHook := hBackgroundBrush;
  110.  
  111.                     CtlColor_ScrollBar,
  112.                     CtlColor_MsgBox,
  113.                     CtlColor_Static :
  114.                         BEGIN
  115.                             { Brush for the background }
  116.                             FileOpenHook := GetStockObject (LTGRAY_BRUSH);
  117.                             { Set the text background color }
  118.                             SetBkColor (wParam, rgbLightGray);
  119.                         END; { case CtlColor_Static }
  120.  
  121.                 END; { case }
  122.             END; { case wm_CtlColor }
  123.     END; { case }
  124. END; { FileOpenHook }
  125.  
  126. (* ---- *)
  127.  
  128. PROCEDURE TStaticApp.InitMainWindow;
  129. { Create the window object }
  130.  
  131. BEGIN
  132.     MainWindow := New (PStaticWindow, Init (NIL, 'MainDialog'));
  133. END; { TStaticApp.InitMainWindow }
  134.  
  135. (* ---- *)
  136.  
  137. CONSTRUCTOR TStaticWindow.Init (AParent: PWindowsObject; ATitle: PChar);
  138. { Initialize the window object }
  139.  
  140. BEGIN
  141.     INHERITED Init (AParent, ATitle); { Call ancestor }
  142.  
  143.     { Initialize the recessed/raised controls }
  144.     { Statics }
  145.     New (pToStaticUp, InitResource (@SELF, id_StaticUp, 25));
  146.     New (pToStaticDown, InitResource (@SELF, id_StaticDown, 25));
  147.     { Frames }
  148.     New (pToFrameUp, InitResource (@SELF, id_FrameUp));
  149.     New (pToFrameDown, InitResource (@SELF, id_FrameDown));
  150. END; { TStaticWindow.Init }
  151.  
  152. (* ---- *)
  153.  
  154. PROCEDURE TStaticWindow.SetupWindow;
  155. { Initialize the controls }
  156.  
  157. BEGIN
  158.     INHERITED SetupWindow; { Call ancestor }
  159.  
  160.     { Put some text into the static controls. Note the leading space. }
  161.     pToStaticUp^.SetText (' Raised static control');
  162.     pToStaticDown^.SetText (' Recessed static control');
  163. END; { TStaticWindow.SetupWindow }
  164.  
  165. (* ---- *)
  166.  
  167. PROCEDURE TStaticWindow.GetWindowClass (VAR AWndClass: TWndClass);
  168.  
  169. BEGIN
  170.     INHERITED GetWindowClass (AWndClass); { Vorfahre aufrufen }
  171. END; { TStaticWindow.GetWindowClass }
  172.  
  173. (* ---- *)
  174.  
  175. FUNCTION TStaticWindow.GetClassName : PChar;
  176.  
  177. BEGIN
  178.     GetClassName := szClassName;
  179. END; { TStaticWindow.GetClassName }
  180.  
  181. (* ---- *)
  182.  
  183. PROCEDURE TStaticWindow.wmCommand (VAR Msg: TMessage);
  184. { Quit program if user presses ESC }
  185.  
  186. BEGIN
  187.     IF (Msg.wParam = idCancel) THEN
  188.     BEGIN
  189.         PostMessage (hWindow, wm_Close, 0, 0);
  190.         Msg.Result := 0;
  191.     END { if }
  192.     ELSE INHERITED wmCommand (Msg);
  193. END; { TStaticWindow.wmCommand }
  194.  
  195. (* ---- *)
  196.  
  197. PROCEDURE TStaticWindow.idChooseFile (VAR Msg: TMessage);
  198. { User pressed the "Select a file" button }
  199.  
  200. CONST
  201.     DefExt = 'exe';
  202.     szFilter = 'Programs'#0'*.exe *.com *.bat *.pif'#0'All files'#0'*.*'#0#0;
  203.     cPathLen = 100;
  204.  
  205. VAR
  206.     pToOpenFN : POpenFileName;
  207.     pacFilter, pacFileName, pacFullFileName : PChar;
  208.     hWndEdit1, hWndEdit2 : hWnd;
  209.  
  210. BEGIN
  211.     New (pToOpenFN);
  212.     GetMem (pacFileName, cPathLen);
  213.     GetMem (pacFullFileName, cPathLen);
  214.  
  215.     { Es wird kein Dateiname ⁿbergeben }
  216.     lstrcpy (pacFileName,  '');
  217.     lstrcpy (pacFullFileName, '');
  218.  
  219.     pacFilter := szFilter;
  220.  
  221.     FillChar (pToOpenFN^, SizeOf (TOpenFileName), #0); { Fill structure }
  222.  
  223.  
  224.     WITH pToOpenFN^ DO
  225.     BEGIN { Initialize structure }
  226.         hInstance := System.hInstance; { Instance handle }
  227.         hWndOwner := hWindow; { Handle of parent window }
  228.         lpStrDefExt := DefExt; { Default extension }
  229.         lpStrFile := pacFullFileName; { Initial filename }
  230.         lpStrFilter := pacFilter; { The list with the extensions }
  231.         lpStrFileTitle := pacFileName; { Full filename including path }
  232.         lpStrTitle := 'Browse for a file'; { Dialog box title }
  233.         { Various flags }
  234.         Flags := ofn_FileMustExist OR ofn_HideReadOnly OR ofn_EnableHook;
  235.         lStructSize := SizeOf (TOpenFileName); { Size of data structure }
  236.         nFilterIndex := 1; { Select the first filter }
  237.         nMaxFile := cPathLen - 1; { Size of buffer }
  238.         lpfnHook := FileOpenHook; { Hook function. $K+ must be enabled!!! }
  239.     END; { with }
  240.  
  241.     IF (GetOpenFileName (pToOpenFN^)) THEN
  242.     BEGIN { Success }
  243.         hWndEdit1 := GetDlgItem (hWindow, id_EditUp);
  244.         hWndEdit2 := GetDlgItem (hWindow, id_EditDown);
  245.  
  246.         SetFocus (hWndEdit1);
  247.  
  248.         { Copy the filename into the parent window's edit controls }
  249.         SendMessage (hWndEdit1, wm_SetText, 0, LongInt (pacFileName));
  250.         SendMessage (hWndEdit2, wm_SetText, 0, LongInt (pacFileName));
  251.  
  252.         { Repaint the edit controls in the parent window in case that the
  253.           user moved the "Browse for a file" dialog. Without the call to
  254.           InvalidateRect the text in the edit controls won't get displayed
  255.           correctly IF the dialog box is over the edit controls. }
  256.         InvalidateRect (hWndEdit1, NIL, TRUE);
  257.         InvalidateRect (hWndEdit2, NIL, TRUE);
  258.     END; { if }
  259.  
  260.     Dispose (pToOpenFN);
  261.     FreeMem (pacFileName, cPathLen);
  262.     FreeMem (pacFullFileName, cPathLen);
  263. END; { TStaticWindow.idChooseFile }
  264.  
  265. (* ---- *)
  266.  
  267. VAR
  268.     StaticApp : TStaticApp;
  269.  
  270. BEGIN { StaticTest }
  271.     WITH StaticApp DO
  272.     BEGIN
  273.         Init (szAppName);
  274.         Run;
  275.         Done;
  276.     END; { with }
  277. END. { StaticTest }
  278.